home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample PMSAM / PMSAM Framework / RoboSamSlot / CTBChannel.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  5.7 KB  |  269 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CTBChannel.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Tim Harnett
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <22>    12/12/94    TMH        added IsOpen()
  13.         <21>    11/17/94    TMH        added Disconnect
  14.         <20>     11/8/94    TMH        changes to support async P3 thread
  15.         <19>     11/2/94    JHB        Adding support for Sending eWorld Mail
  16.         <18>     11/2/94    TMH        added no carrier detect stuff, and WriteBytes
  17.         <17>    10/28/94    TMH        added FlushRead,FlushWrite and some other stuff
  18.         <16>    10/28/94    TMH        made async and X25 work better
  19.         <15>    10/25/94    TMH        made open,close, read & write asynchronous
  20.         <13>    10/21/94    TMH        created TModemChannel and TX25Channel
  21.         <11>    10/20/94    TMH        added IsToolMacPad() etc
  22.         <10>    10/18/94    TMH        pass external slot to ICTBChannel
  23.         <10>    10/18/94    TMH        pass external slot to ICTBChannel
  24.  
  25.     To Do:
  26. */
  27.  
  28.  
  29. #ifndef    _CTBCHANNEL_
  30. #define _CTBCHANNEL_
  31.  
  32.  
  33. class    TWakeupThread;
  34. class    TCTBIdleThread;
  35.  
  36. #ifndef __ExternalSlot__
  37. #include "ExternalSlot.h"
  38. #endif
  39.  
  40. #ifndef __PMSAMResources__
  41. #include "PMSAMResources.h"
  42. #endif
  43.  
  44. #ifndef    __CONNECTIONS__
  45. #include <Connections.h>
  46. #endif
  47.  
  48. #ifndef __LogErrors__
  49. #include "LogErrors.h"
  50. #endif
  51.  
  52. #ifndef __TThread__
  53. #include "TThread.h"
  54. #endif
  55.  
  56.  
  57. #define kDontWaitForPending    true
  58. #define kWaitForPending        false
  59.  
  60. #define kDoAsync        true
  61. #define kDoSync            false
  62.  
  63. // defines for the various connection networks
  64.  
  65. #define            NO_NETWORK                    0
  66. #define            SPRINTNET                    1
  67. #define            MCI                            2
  68.  
  69.  
  70. inline Boolean IsCTBError(CMErr cmErr) { return  (cmErr > 0) && (cmErr <= cmUnknownError); };
  71.  
  72. //-----------------------
  73. //    T C T B C h a n n e l
  74. //---------------------------
  75.  
  76. class    TCTBChannel {
  77.  
  78. public:
  79.                         TCTBChannel( );
  80.                         ~TCTBChannel( );
  81.  
  82.         void            ICTBChannel(short toolParamResID, StringPtr toolName, TExternalSlot* slot );
  83.         void            SetCTBParametersFromResource(short resID);
  84.  
  85.  
  86.             //--------------------
  87.             //    Reading & Writing
  88.             //--------------------
  89.             
  90.             
  91.         CMErr            Read ( char *theBuffer, long bytesToRead, long timeOut);
  92.         CMErr            Write ( char *theBuffer, long bytesToWrite, long timeOut);
  93.  
  94.  
  95.             //    these ones FAIL
  96.         char            ReadByte();
  97.         void            ReadBytes(char *theBuffer, long bytesToRead );
  98.  
  99.  
  100.         void            Waitfor( short time);
  101.         char            WaitFor(char waitFor);
  102.         char            WaitForOneOf(char *searchString);    //  wait 'oneof' found or timeout fail
  103.         
  104.         void            WaitForString (char* searchString);    //    wait till success or timeout fail
  105.         void            SendString(char* sendString);        //    wait till success or timeout fail
  106.  
  107.  
  108.         void            WriteBytes(void* data, long dataLen);
  109.         
  110.             //-------
  111.             //    Misc.
  112.             //-------
  113.             
  114.         void            IdleChannel();
  115.         void             FlushRead( );
  116.         void             FlushWrite( );
  117.         
  118.  
  119.  
  120.             //--------------
  121.             //    Accessors
  122.             //--------------
  123.             
  124.             
  125.         long            OpenTimeout() { return fOpenTimeout; };
  126.         long            CloseTimeout() { return fCloseTimeout; };
  127.         long            ReadTimeout() { return fReadTimeout; };
  128.         long            WriteTimeout() {  return fWriteTimeout; };
  129.  
  130.  
  131.         CMStatFlags        GetCMStatus();
  132.         Boolean            IsOpen();
  133.         
  134.         Boolean            IsIOPending();
  135.         Boolean            IsOpenPending();
  136.         Boolean            IsReadPending();
  137.         Boolean            IsWritePending();
  138.         long            DataAvail();
  139.         CMErr            KillAllIO();
  140.         CMErr            Abort();
  141.         
  142.         
  143.             //-----------------
  144.             //    Connecting
  145.             //-----------------
  146.  
  147.             OSErr        Connect(Ptr configStr);
  148.     virtual void        MakeConnection() = 0;
  149.             void        Disconnect();
  150.             
  151.             CMErr        Open();
  152.             CMErr        Close();
  153.             
  154.     virtual void        NetworkLogin();
  155.     
  156.         
  157. protected:
  158.  
  159.     static  pascal    void        __CTBCompletorProc(ConnHandle    theConnectionHandle);
  160.  
  161. private:
  162.                 void        InitializeCTB();
  163.  
  164. protected:
  165.  
  166.  
  167.         CommState                    fCommState;
  168.         ConnHandle                    fConnH;                    // the Connection Handle for the channel
  169.  
  170.  
  171.         TWakeupThread*    fWakeupThread;            //    for async I/O
  172.         TExternalSlot*    fExternalSlot;
  173.  
  174.  
  175.             //    CTB Parameters
  176.             
  177.             
  178.         long            fReadTimeout;
  179.         long            fWriteTimeout;
  180.         long            fOpenTimeout;
  181.         long            fCloseTimeout;
  182.  
  183.         
  184.         Boolean            fOpenASync;
  185.         Boolean            fCloseASync;
  186.         Boolean            fReadASync;
  187.         Boolean            fWriteASync;
  188.         
  189.         long            fConfigBufSize;
  190.  
  191.         long            fBaudRate;                // baud rate for modems, 0 if not using modem tool (like for X.25)
  192.  
  193. private:
  194.                         
  195.         ConnEnvironRec    fConnEnvironRec;        // the ConnEvironRec for the channel (connection environment record)
  196.                                                 // has the CMChannel, CMFlags, as well as version, baudrate, databits and flowControl settings
  197.  
  198.         CMBufferSizes    fBufferSizesArray;        // holds the sizes of the various CTB buffers for each CTB channel
  199.  
  200.         TCTBIdleThread*    fCTBIdleThread;
  201. };
  202.  
  203.  
  204.  
  205.  
  206. //---------------------------
  207. //    T M o d e m C h a n n e l
  208. //---------------------------
  209.  
  210. class TModemChannel : public TCTBChannel {
  211. public:
  212.                     TModemChannel();
  213.             void    IModemChannel(StringPtr toolName, TExternalSlot* exSlot);
  214.  
  215.     virtual void    NetworkLogin();
  216.     virtual void    MakeConnection();
  217.     
  218.             void    ClearNoCarrierDetected() { fNoCarrierDetected = false; };
  219. private:
  220.                     void         SprintNetLogin ();
  221.     static    pascal    void        NoCarrierDetectProc(ConnHandle hConn,Ptr matchPtr,long refNum);
  222.  
  223. private:
  224.                     short        fAccessNetwork;
  225.                     
  226.                     long        fNoCarrierDetectRefNum;        // value returned from CMAddSearch
  227.                     Boolean        fNoCarrierDetected;            //    set by NoCarrierDetectProc
  228.  
  229. };
  230.  
  231.  
  232. //---------------------------
  233. //    T X 2 5 C h a n n e l
  234. //---------------------------
  235.  
  236. class TX25Channel : public TCTBChannel {
  237. public:
  238.                     TX25Channel();
  239.             void    IX25Channel(StringPtr toolName, TExternalSlot* exSlot);
  240.             
  241.     virtual void    NetworkLogin();
  242.     virtual void    MakeConnection();
  243.  
  244. };
  245.  
  246.  
  247. //-------------------------------------
  248. //     T C T B I d l e T h r e a d
  249. //--------------------------------------
  250.  
  251. #define kCTBIdleThreadStackSize 16000
  252. class TCTBIdleThread : public TCooperativeThread {
  253.  
  254. public:    
  255.                         TCTBIdleThread();
  256.             void        ICTBIdleThread(TCTBChannel* ctbChannel);
  257.     
  258.     virtual void*        ThreadMain();
  259.     
  260. private:
  261.     TCTBChannel* fCTBChannel;
  262. };
  263.  
  264.  
  265.  
  266. #endif
  267.  
  268.  
  269.